﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Valentia.Kinection.DataTypes;

namespace Valentia.Kinection.Watchdog
{
    partial class WatchdogService : ServiceBase
    {
        /// <summary>
        /// Kinection watchdog service name.
        /// </summary>
        public const String ThisServiceName = "Valentia Kinection Service Watchdog";

        /// <summary>
        /// Kinect device watchdog
        /// </summary>
        private KinectWatchDog watchDog;

        public WatchdogService()
        {
            InitializeComponent();
            this.ServiceName = WatchdogService.ThisServiceName;
        }

        protected override void OnStart(string[] args)
        {
            try
            {

                this.watchDog = new KinectWatchDog();
                this.watchDog.Start();

                Logger.Log("Service started successfully");
            }
            catch (Exception exp)
            {
                Logger.Log(exp, "Stopping service failed due to exception");
                throw;
            }
        }

        protected override void OnStop()
        {
            { try { this.watchDog.Dispose(); } catch { } }
            Logger.Log("Service stopped successfully");
        }
    }
}
